package com.www.applyword.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.www.applyword.R;
import com.www.applyword.bean.AllPositionListBean;
import com.www.applyword.event.EventConstants;
import com.www.applyword.event.MessageEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

public class GirdDropDownAdpter2 extends BaseAdapter {
    private Context context;
    private List<AllPositionListBean> beanList;
    private LayoutInflater inflater;



    public GirdDropDownAdpter2(Context context, List<AllPositionListBean> beanList) {
        this.context = context;
        this.beanList = beanList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int position) {
        return beanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_list_position,null);
            holder.item_city_name_tv = convertView.findViewById(R.id.tv);
            holder.rl_job_workfare = convertView.findViewById(R.id.rl_job_workfare);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
         AllPositionListBean allPositionListBean = beanList.get(position);
         holder.item_city_name_tv.setText(allPositionListBean.getParent().getPosition_Name());
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        holder.rl_job_workfare.setLayoutManager(layoutManager);
        JobPositionAdapter3  jobPositionAdapter3 = new JobPositionAdapter3(context);
        holder.rl_job_workfare.setAdapter(jobPositionAdapter3);
        jobPositionAdapter3.replaceAll(allPositionListBean.getSonList(), true);
        jobPositionAdapter3.setOnItemClickListener((viewHolder, view, i) -> {
            MessageEvent messageEvent = new MessageEvent();
            messageEvent.setMessageKey(EventConstants.POSITION);
            messageEvent.setMessageValue(allPositionListBean.getSonList().get(i).getPosition_ID());
            EventBus.getDefault().post(messageEvent);
        });
        return convertView;
    }

    class ViewHolder {
        private TextView item_city_name_tv;
        private RecyclerView rl_job_workfare;
    }
}
